package com.crm.mapper.system;

import com.crm.dto.QueryEmpTypeDto;
import com.crm.pojo.Dept;
import com.crm.vo.TbUserVo;
import com.crm.vo.TreeselectVO;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface DeptMapper {

    List<Dept> list(String status, String deptName);


    @Select("select  *from tb_dept where dept_id=#{deptId}")
    Dept getByDeptId(Integer deptId);

    @Select("select  *from tb_dept")
    List<Dept> getByDeptIdlist();

    @Select("select *from tb_dept where dept_id=#{parentId}  ")
    Dept searchAll(Integer parentId);

    @Insert("insert into tb_dept( dept_id, parent_id, ancestors, dept_name, order_num, leader, phone, email, status, del_flag, parent_name, create_time, update_time, create_by, update_by)" +
            "values (#{deptId},#{parentId},#{ancestors},#{deptName},#{orderNum},#{leader},#{phone},#{email},#{status},#{delFlag},#{parentName},#{createTime},#{updateTime},#{createBy},#{updateBy})")
    void add(Dept deptNew);

    void update(Dept dept);

    @Select("select * from tb_dept where parent_id=#{deptId}")
    List<Dept> getDeptId(Integer deptId);

    @Delete("delete from tb_dept where dept_id=#{deptId}")
    void delete(Integer deptId);

    @Select("select dept_id id,parent_id,dept_name label from tb_dept")
    List<TreeselectVO> selectAllDepts();

    Page<TbUserVo> page(QueryEmpTypeDto dto);
}
